package com.ruoyi.dataserver.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * @ProjectName intelligent-city
 * @Package com.lab.dataserver.utils
 * @ClassName NumberUtils
 * @Description 数字工具类
 * @Company LAB
 * @Author LXK
 * @Date 2020/7/9 14:15
 * @UpdateUser
 * @UpdateDate
 * @UpdateRemark
 * @Version 1.0.0
 */
public class NumberUtils {
    /**
     * 根据整数跨度获得跨度区间
     * @param start  开始位
     * @param end    结束位
     * @param span   跨度
     * @return
     */
    public static List getIntegerIntervalBySpan(int start, int end, int span){
        List integerSpan = new ArrayList();
        int temp = 0;
        int spanStart = 0;
        while ( true ){
            if( temp == 0 ){
                spanStart= start;
                temp = start+span;
            }else{
                spanStart= temp;
                temp +=span;
            }
            if( temp < end ){
                List templist = new  ArrayList();
                templist.add(spanStart);
                templist.add(temp);
                integerSpan.add(templist);
                continue;
            }else if( temp == end ){
                List templist = new  ArrayList();
                templist.add(spanStart);
                templist.add(end);
                integerSpan.add(templist);
                continue;
            }
            break;
        }
        return  integerSpan;
    }
    /**
     * 根据浮点数跨度获得跨度区间
     * @param start  开始位
     * @param end    结束位
     * @param span   跨度
     * @return
     */
    public static List getDoubleIntervalBySpan(double start, double end, double span){
        List doubleSpan = new ArrayList();
        double temp = 0.00;
        double spanStart = 0.00;
        while ( true ){
            if( temp == 0.00 ){
                spanStart= start;
                temp = start+span;
            }else{
                spanStart= temp;
                temp +=span;
            }
            if( temp < end ){
                List templist = new  ArrayList();
                templist.add(spanStart);
                templist.add(temp);
                doubleSpan.add(templist);
                continue;
            }else if( temp == end ){
                List templist = new  ArrayList();
                templist.add(spanStart);
                templist.add(end);
                doubleSpan.add(templist);
                continue;
            }
            break;
        }
        return  doubleSpan;
    }



}
